/* Copyright 203-2115 AtomWare Technology Pty Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * The flowing information must be keep 
 * ZtreeNodeAction.java
 * appbasic
 * 2013年11月26日上午10:45:48
 * @author 屈甲康
 * QQ285799123
 * mailto:qujiakang@gmail.com
 */

package org.jackysoft.controller;

import java.util.Collection;
import java.util.HashMap;

import javax.annotation.Resource;

import org.jackysoft.controller.base.AbstractController;
import org.jackysoft.entity.Department;
import org.jackysoft.entity.OsRuntimeContext;
import org.jackysoft.entity.Role;
import org.jackysoft.service.OsRuntimeContextService;
import org.jackysoft.workflow.ActionItem;
import org.jackysoft.workflow.StepOwner;
import org.jackysoft.workflow.Workflow;
import org.jackysoft.ztree.ZTreeNode;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.google.common.collect.Lists;

@Controller
@RequestMapping("/ZtreeNode")
public class ZtreeNodeController extends AbstractController<ZTreeNode> {

	@Resource
	OsRuntimeContextService rcService;
	
	@Resource
	Workflow workflow;
	
	public String userview(
			int actionId,
			long refid,
			long stepId,
			@ModelAttribute ActionItem actionItem,
			@ModelAttribute Collection<StepOwner> nextOwners,
			@ModelAttribute boolean auto
			) throws Exception {
		actionItem = workflow.getActionItemById(actionId, refid,new HashMap<String,Object>());
		stepId = actionItem.getStepId();
		OsRuntimeContext setting = rcService.findOne(refid, actionId, stepId);
		if (setting != null && setting.getValue() != null) {
			nextOwners = Lists.newArrayList();
			StepOwner so = new StepOwner();
			so.setOwner(setting.getValue());
			so.setStepId(stepId + "");
			nextOwners.add(so);
			auto = true;
			return "proceed";
		}
		return "userview";
	}
	
}
